// pages/rVouncerInfo/index.js
const app = getApp()

const getInf = (str, key) => str.toString().replace(new RegExp(`${key}`, 'g'), `%%${key}%%`).split('%%');

import {
  httpRequest,

} from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getinput:false,
    color:'blue',
    parking:[],
    copyparking:[],
    hasK:false,
    value:'',
    parkinName:''
      // {"text":'dasda'},
      // {"text":'uiomik'},
      // {"text":'6gyiujn'},
      // {"text":'dsak'},
      // {"text":'bllll'},
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  return(){
    wx.navigateBack({
      delta: 1,
    })
  },
  close(){
    this.setData({
      getinput:false
    })
  },
  formSubmit(e){
    let value = e.detail.value
    for(let i in value){
      
      if(value[i]==''){
        this.setData({
          hasK:true
        })
        wx.showModal({
          title:'提示',
          content:'您有未填的内容'
        })
        break
      } 
    }
    if(!this.data.hasK){
      wx.showModal({
        title:"提示",
        content:"是否确定提交审核？",
        confirmColor:"#0058FF",
        cancelColor:"#DB4141",
        success:function(res){
          if(res.confirm){
            let userId = wx.getStorageSync('userId')
            // httpRequest("/merchant",'POST',{...e.detail.value,userId:userId}).then(res=>{
            httpRequest("/merchant",'POST',{...e.detail.value,userId:userId}).then(res=>{
              if(res.data.code == 200){
                wx.showToast({
                  title: '注册成功',
                })
              }
             
              console.log(res)
            })
            // wx.navigateTo({
            //   url: '/pages/voucher/index',
            // })
          }
        }
      })
    }
    
  },
 
  getparkings(e){
    let that = this
    let value = e.detail.value
    that.setData({
      value:value.replace(/\s+/g,'')
    })
    wx.request({
      url: app.globalData.basicUrl+'system/parking/findAll',
      success: function (res) {
        let parking = res.data.data
        let copyparking = parking
        var data = parking;
        var newData = copyparking;
        let s =[]
        for (var i = 0; i < data.length; i++) {
          var dic = data[i];
          var newDic = newData[i];
          var f = dic["parkingName"]
          newDic["parkingName"] = getInf(f,value)
          s.push(newDic)
        }
     
        that.setData({
          parking:s
        })
      }
    })
    

    if(value.length>0){
      that.setData({
        getinput:true
      })
    }else{
      that.setData({
        getinput:false
      })
    }
  
  },
  chooseParking(e){
    this.setData({
      parkinName:e.currentTarget.dataset.item
    })
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})